#include <vector>

using std::vector;

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int len = nums.size();
        if (len <= 2) {
            return len;
        }
        int i = 2, j = 2;
        while (j < len) {
            if (nums[j] != nums[i - 2]) {
                nums[i++] = nums[j];
            }
            j++;
        }
        return i;
    }
};